﻿@{
    Layout = null;
}

<html>
<head>
    <title>创建详细日程模版</title>
</head>
<body>
    <div>
        <div style="margin: 10px 0px 10px 30px; float: left">
            <div class="ls_btn_imi" id="btnBack" onclick="Lscheduler.getCursorPosition(document.getElementById('txtMinDate'))">
                <div class="ls_icon_back" style="margin: 7px 0px 0px 34px">
                </div>
            </div>
            <div class="ls_btn_imi" id="btnCreate" style="margin-left: 20px;">
                创建
            </div>
        </div>
        <div class="ls_split_line" style="float: left"></div>
        <div style="margin: 10px 0px 10px 30px; float: left;">
            <div>
                <input type="text" id="txtSubject" class="ls_txt1" style="width: 600px; font-size: 16px;" value="我的活动" />
            </div>
            <div style="margin-top: 5px;">
                <input type="text" id="txtMinDate" class="ls_txt1" style="width: 80px;" value="2013-08-25" />
                <input type="text" id="txtMinTime" class="ls_txt1" style="width: 42px;" value="" />
                <span style="font-size: 13px;">到</span>
                <input type="text" id="txtMaxDate" class="ls_txt1" style="width: 80px;" value="2013-08-25" />
                <input type="text" id="txtMaxTime" class="ls_txt1" style="width: 42px;" value="14:30" />
            </div>
            <div style="margin-top: 5px;">
                <table style="font-size: 13px;">
                    <tr>
                        <td class="ls_topright">活动颜色：</td>
                        <td>
                            <div id="div_coolor_choose">
                                <div class="ls_color_dis" style="background-color: #5484ed; border: 1px solid #5484ed" title="宝石蓝"></div>
                                <div class="ls_color_dis" style="background-color: #a4bdfc; border: 1px solid #a4bdfc" title="蓝色"></div>
                                <div class="ls_color_dis" style="background-color: #46d6db; border: 1px solid #46d6db" title="青绿色"></div>
                                <div class="ls_color_dis" style="background-color: #7ae7bf; border: 1px solid #7ae7bf" title="绿色"></div>
                                <div class="ls_color_dis" style="background-color: #51b749; border: 1px solid #51b749" title="清新绿"></div>
                                <div class="ls_color_dis" style="background-color: #fbd75b; border: 1px solid #fbd75b" title="黄色"></div>
                                <div class="ls_color_dis" style="background-color: #ffb878; border: 1px solid #ffb878" title="橙色"></div>
                                <div class="ls_color_dis" style="background-color: #ff887c; border: 1px solid #ff887c" title="红色"></div>
                                <div class="ls_color_dis" style="background-color: #dc2127; border: 1px solid #dc2127" title="奢华红"></div>
                                <div class="ls_color_dis" style="background-color: #dbadff; border: 1px solid #dbadff" title="紫色"></div>
                                <div class="ls_color_dis" style="background-color: #e1e1e1; border: 1px solid #e1e1e1" title="灰色"></div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="ls_topright">活动说明：
                        </td>
                        <td>
                            <textarea style="resize: none; height: 100px; width: 557px" class="ls_txt1"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <div style="height: 200px; background-color: red; width: 200px; overflow: hidden">
        <div style="height: 300px; background-color: blue; width: 100px"></div>
    </div>
</body>
</html>
<script type="text/javascript">
    var Lscheduler = {};
</script>
<script src="@(Url.Content("~/Scripts/scheduler.utility.js"))"></script>
<script src="@(Url.Content("~/Scripts/scheduler.calendar.js"))" type="text/javascript"></script>
<script type="text/javascript">
    var buttons = ["btnBack", "btnCreate"];
    for (var i in buttons) {
        var button = document.getElementById(buttons[i]);
        (function (a) {
            Lscheduler.attachEvent(a, "mouseover", function () {
                a.style.boxShadow = "0 0 5px #848484";
            });
            Lscheduler.attachEvent(a, "mouseout", function () {
                a.style.boxShadow = "";
            });
            Lscheduler.attachEvent(a, "mousedown", function () {
                a.style.boxShadow = "inset 0 0 5px #848484";
            });
            Lscheduler.attachEvent(a, "mouseup", function () {
                a.style.borderColor = "";
            });
        })(button);
    }
    var v_c = document.getElementById("div_coolor_choose");
    for (var i = 0; i < v_c.childNodes.length; i++) {
        if (v_c.childNodes[i].className != "ls_color_dis" && v_c.childNodes[i].tagName != "DIV") {
            continue
        }
        (function (node) {
            Lscheduler.attachEvent(node, "mouseover", function () {
                if (!node.getAttribute("lc")) {
                    node.setAttribute("lc", node.style.borderColor);
                }
                node.style.borderColor = "#000000";
            });
            Lscheduler.attachEvent(node, "mouseout", function () {
                node.style.borderColor = node.getAttribute("lc");
            });
            Lscheduler.attachEvent(node, "click", function () {
                var choosed = document.getElementById("div_ls_color_choosed");
                if (!choosed) {
                    choosed = document.createElement("div");
                    choosed.id = "div_ls_color_choosed";
                    choosed.style.margin = "3px 0px 0px 2px";
                    choosed.className = "ls_color_choosed";
                }
                node.appendChild(choosed);
            });
        })(v_c.childNodes[i]);
    }

    document.getElementById("txtMinDate").onfocus = function () {
        Lscheduler.calendar.pick(this, {
            minDate: "2013-08-31",
            maxDate: "2013-09-05"
        });
    }

    var lastValue = "";
    Lscheduler.registerTimeLimit(document.getElementById("txtMaxTime"));
    document.getElementById("txtMinTime").onkeydown = function (event) {
        if ((parseInt(event.key) >= 0 && parseInt(event.key) <= 9) || event.key == ":") {
            lastValue = this.value;
            var content = Lscheduler.insertCharacter(this.value, event.key, Lscheduler.getCursorPosition(this));
            if (content.length == "1") {

            }
            else if (content.length == 2) {
                if (/^([0-1][0-9]|[2][0-3]|[0-9]:?|:[0-5])$/.test(content)) {
                    if (content.indexOf(":") == -1) {
                        this.value = content + ":";
                        return false;
                    }
                }
                else {
                    return false;
                }
            }
            else if (content.length == 3) {
                if (/^(([0-1][0-9]|[2][0-3]):)$/.test(content)) {
                    this.value = content;
                    Lscheduler.setCursorPosition(this, content.length);
                    return false;
                }
                else if (/^:[0-5][0-9]/.test(content)) {
                    this.value = content;
                    Lscheduler.setCursorPosition(this, 0);
                    return false;
                }
                else if (!/^([0-9]:[0-9])$/.test(content)) {
                    return false;
                }
            }
            else if (content.length == 4) {
                if (!/^((([0-1][0-9]|[2][0-3]):[0-9])|([0-9]:[0-5][0-9]))$/.test(content)) {
                    return false;
                }
            }
            else if (content.length == 5) {
                if (!/^([0-1][0-9]|[2][0-3]):[0-5][0-9]$/.test(content)) {
                    return false;
                }
            }
            else {
                return false;
            }
        }
        else if (event.key == ":") {
            if (event.key == ":" && ((this.value.indexOf(":") == -1 && !/^([0-1][0-9]|[2][0-3]|[0-9])$/.test(this.value)) || this.value.indexOf(":") > -1)) {
                return false;
            }
        }
        else if (event.keyCode == 8) {
            var pos = Lscheduler.getCursorPosition(this);
            var c = this.value.substr(pos - 1, 1);
            if (c == ":") {
                Lscheduler.setCursorPosition(this, pos - 1);
                return false;
            }
        }
        else if (event.keyCode == 46) {
            var pos = Lscheduler.getCursorPosition(this);
            var c = this.value.substr(pos, 1);
            if (c == ":") {
                Lscheduler.setCursorPosition(this, pos + 1);
                return false;
            }
        }
        else if (!((event.keyCode >= 37 && event.keyCode <= 40) || event.keyCode == 46 || event.keyCode == 9 || event.keyCode == 16)) {
            return false;
        }
    }
    document.getElementById("txtMinTime").onblur = function () {
        var content = this.value;
        if (content.length == 0 || content == ":") {
            this.value = "00:00";
        }
        else if (content.length == 1) {
            if (/^\d$/.test(content)) {
                this.value = "0" + content + ":00";
            }
        }
        else if (content.length == 2) {
            if (/^[0-1][0-9]|[2][0-3]$/.test(content)) {
                this.value = content + ":00";
            }
            else if (/^[0-9]:$/.test(content)) {
                this.value = "0" + content + "00";
            }
            else if (/^:[0-9]$/.test(content)) {
                this.value = "00:0" + content.substr(1, 1);
            }
            else if (/^2[4-9]|[3-5][0-9]$/.test(content)) {
                this.value = "00:" + content;
            }
        }
        else if (content.length == 3) {
            if (/^[0-1][0-9]|[2][0-3]:$/.test(content)) {
                this.value = content + "00";
            }
            else if (/^[0-9]:[0-9]$/.test(content)) {
                this.value = "0" + content.substr(0, 2) + "0" + content.substr(2, 1);
            }
            else if (/^:[0-5][0-9]$/.test(content)) {
                this.value = "00" + content;
            }
        }
        else if (content.length == 4) {
            if (/^([0-1][0-9]|[2][0-3]):[0-9]$/.test(content)) {
                this.value = content.substr(0, 3) + "0" + content.substr(3, 1);
            }
            else if (/^[0-9]:[0-5][0-9]$/.test(content)) {
                this.value = "0" + content;
            }
        }
    }
    //document.getElementById("txtMinTime").onkeyup = function (event) {
    //    if (this.value.length < 5) {
    //        return;
    //    }
    //    var timereg = /^([0-1][0-9]|[2][0-3]):[0-5][0-9]$/
    //    if (!timereg.test(this.value)) {
    //        this.value = lastValue;
    //    }
    //}

    document.getElementById("btnCreate").onclick = function () {
        //selectLength(document.getElementById("txtMinTime"), 1, 4);
        alert(Lscheduler.getCursorPosition(document.getElementById("txtMinDate")));
    }

    function selectLength(textbox, start, len)   //设置高亮(对象,开始位置,长度)
    {
        try {
            var r = textbox.createTextRange();
            r.moveEnd('character', len - (textbox.value.length - start));
            r.moveStart('character', start);

            r.select();
        }
        catch (e) {
        }

    }
</script>
<style type="text/css">

</style>
<link href="@(Url.Content("~/Content/scheduler.css"))" rel="stylesheet" />
